package memento.generalv1;

import memento.generalv1.Memento;

/**
 * @Author：LJ
 * @Description：发起人橘色
 * @Date: 2017/12/1
 * @Modified By:
 */
public class Originator {

    private String state;
    private String state1;
    private String state2;

    public String getState1() {
        return state1;
    }

    public void setState1(String state1) {
        this.state1 = state1;
    }

    public String getState2() {
        return state2;
    }

    public void setState2(String state2) {
        this.state2 = state2;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    //创建一个备忘录
    public Memento createMemento() throws CloneNotSupportedException {
        return new Memento(BeanUtils.backupProp(this));
    }

    //恢复一个备忘录
    public void restoreMemento(Memento memento) {
        //在恢复之前应该进行断言,防止空指针
        BeanUtils.restoreProp(this, memento.getStates());
    }

    @Override
    public String toString() {
        return "state=" + state + "\tstate1=" + state2 + "\tstate2=" + state2;
    }
}
